<template>
    <van-nav-bar title="分销会员" />

    <van-pull-refresh v-model="refreshing" @refresh="OnRefresh">
        <van-list
            v-model:loading="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="OnLoad"
        >
            <div class="retailmember">
                <div class="item" v-for="(item,index) in list" :key="index">
                    <div class="left">
                        <div class="img">
                            <img :src="item.avatar_cdn" />
                        </div>
                        <div class="content">
                            <div class="nickname">{{ item.nickname }}</div>
                            <div class="tel">{{ item.mobile_text }}</div>
                        </div>
                    </div>
                    <div class="right">2024-04-25</div>
                </div>
            </div>
        </van-list>
    </van-pull-refresh>

    <Tabbar />
</template>

<script setup>
const { proxy } = getCurrentInstance();

const business = proxy.$business;

// 下拉刷新状态
const refreshing = ref(false);

// 加载状态
const loading = ref(false);

// 上拉加载结束状态
const finished = ref(false);

// 当前页
const page = ref(1);
// 数据
const list = ref([]);

// 下拉刷新函数
const OnRefresh = () =>
{
    refreshing.value = true;
    list.value = [];
    finished.value = false;
    loading.value = true;
    page.value = 1;

    setTimeout(OnLoad,1500);
}

// 上拉加载函数
const OnLoad = async () =>
{
    if(refreshing.value === true) refreshing.value = false;

    const params = {
        page:page.value,
        busid:business.value.id
    }

    const result = await proxy.$http.post({
        url:'/sale/business',
        params
    });

    loading.value = false;

    if(result.code === 1)
    {
        const count = result.data.count;
        list.value = list.value.concat(result.data.list);

        if(list.value.length >= count)
        {
            // 没数据就停止触发OnLoad
            finished.value = true;

            return false;
        }

        page.value += 1;
    }else{
        finished.value = true;

        proxy.$fail(result.msg);
    }
}

</script>

<style scoped>
@import url('/assets/css/SaleBusiness.css');
</style>
